package com.agent.diagnostic;

import java.text.SimpleDateFormat;
import java.util.Calendar;

/*
 * message class : it use to format and do something before print out
 */
public class MessageLog {
	
	private TraceLevel m_typeLog = TraceLevel.NONE;
	private String m_logMessage = "";
	public static final String DATETIME_FORMAT_TA = "yyyy-MM-dd HH:mm:ss";
	
	MessageLog(String message,TraceLevel typeLog){
		m_typeLog = typeLog;
		formatMessage(message);
	}
	/*
	 * format message 
	 */
	private void formatMessage(String message){
		String sTypeLog = "";
		
		switch(m_typeLog){
			case ERROR:
				sTypeLog = "ERROR: ";
				break;
			case WARNING:
				sTypeLog = "WARNING :";
				break;
			case INFO:
				sTypeLog = "INFO";
				break;
		default:
			break;
		}
		
		m_logMessage = String.format("[%s][%s] %s\n", now(),sTypeLog,message);
	}
	/*
	 * get message to print out
	 */
	public String getMessage(){
		return m_logMessage;
	}
	
	/**
	 * Get current date time in TA standard format
	 * @return
	 */
	public static String now(){
	    Calendar cal = Calendar.getInstance();
	    SimpleDateFormat sdf = new SimpleDateFormat(DATETIME_FORMAT_TA);
	    return sdf.format(cal.getTime());
	}
}
